package com.lino.design;

import java.util.HashMap;
import java.util.Map;

/**
 * @description: 校长
 * @author: lingjian
 * @createDate: 2022/12/14 14:47
 */
public class Principal {

    private Teacher teacher = new Teacher("丽华", "3年1班");

    public Map<String, Object> queryClazzInfo(String clazzId) {
        // 获取班级信息，学生总人数、总分、平均分
        int stuCount = clazzStudentCount();
        double totalScore = clazzTotalScore();
        double averageScore = clazzAverageScore();

        // 组装对象，实际业务开发会有对应的类
        Map<String, Object> mapObj = new HashMap<>(16);
        mapObj.put("班级", teacher.getClazz());
        mapObj.put("老师", teacher.getName());
        mapObj.put("学生人数", stuCount);
        mapObj.put("班级总分数", totalScore);
        mapObj.put("班级平均分", averageScore);
        return mapObj;
    }

    /**
     * 平均分
     */
    private double clazzAverageScore() {
        double totalScore = 0;
        for (Student stu : Teacher.getStudentList()) {
            totalScore += stu.getGrade();
        }
        return totalScore / Teacher.getStudentList().size();
    }

    /**
     * 总分
     */
    private double clazzTotalScore() {
        double totalScore = 0;
        for (Student stu : Teacher.getStudentList()) {
            totalScore += stu.getGrade();
        }
        return totalScore;
    }

    /**
     * 总人数
     */
    private int clazzStudentCount() {
        return Teacher.getStudentList().size();
    }


}
